package utils

import (
	"git.myscrm.cn/golang/stark/v4"
	"time"
)

// GetLatestPeriod 获取 "近段时间"
func GetLatestPeriod(timeStr string) string {
	if timeStr == "" {
		return timeStr
	}
	parsedDate, err := time.Parse("2006-01-02 15:04:05", timeStr)
	if err != nil {
		stark.Logger.Errorf(nil, "时间转换失败，err:%+v", err)
	}

	nowTimeUnix := time.Now().Unix()
	targetTimeUnix := parsedDate.Unix()

	if (nowTimeUnix - targetTimeUnix) < 60*60*24*7 {
		return "最近一周更新"
	} else if (nowTimeUnix - targetTimeUnix) < 60*60*24*30 {
		return "最近一个月更新"
	}

	return timeStr
}
